package com.zide.member.controller.community;

import com.zide.common.core.domain.CommonResult;
import com.zide.common.core.domain.PageResult;
import com.zide.member.service.community.CommunityCategoryService;
import com.zide.member.vo.result.community.CommCategoryResultVO;
import com.zide.member.vo.save.community.CommCategorySaveVO;
import com.zide.member.vo.search.community.CommCategorySearchVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zide.common.core.domain.CommonResult.getResult;
import static com.zide.common.core.domain.CommonResult.success;

/**
 * @author 石添
 * @date 2024/8/24
 */
@Slf4j
@RestController
@RequestMapping("/community/category")
@Tag(name = "养宠资信分类管理")
@RequiredArgsConstructor
public class CommunityCategoryController {

    private final CommunityCategoryService communityCategoryService;

    @Operation(summary = "社区分类列表")
    @GetMapping("page")
    public CommonResult pageList(CommCategorySearchVO searchVO) {
        PageResult<CommCategoryResultVO> result = communityCategoryService.pageList(searchVO);
        return success(result);
    }

    @Operation(summary = "社区分类列表")
    @GetMapping("list")
    public CommonResult list(CommCategorySearchVO searchVO) {
        List<CommCategoryResultVO> result = communityCategoryService.searchList(searchVO);
        return success(result);
    }

    @Operation(tags = "添加社区分类")
    @PostMapping
    public CommonResult addCategory(@RequestBody CommCategorySaveVO saveVO) {
        return getResult(communityCategoryService.addCategory(saveVO));
    }

    @Operation(tags = "修改社区分类")
    @PutMapping
    public CommonResult modifyCategory(@RequestBody CommCategorySaveVO saveVO) {
        return getResult(communityCategoryService.modifyCategory(saveVO));
    }

    @Operation(tags = "删除社区分类")
    @DeleteMapping
    public CommonResult removeCategory(@RequestBody Long[] ids) {
        return getResult(communityCategoryService.removeCategory(ids));
    }

    @Operation(summary = "社区分类列表")
    @GetMapping("detail/{id}")
    public CommonResult searchDetail(@PathVariable("id") Long id) {
        return success(communityCategoryService.searchDetail(id));
    }
}
